﻿using System;
using System.Data;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseData;
using BaseData.UI;
using TaxBiz.SysConfig;
using TaxBiz.House;
using TaxEntity.House;

namespace Admin.House
{
    public partial class ZiyongModify : BaseCommon.BasePage
    {
        protected string id = string.Empty;
        protected RentInfoBiz rib = new RentInfoBiz();
        protected RentInfoEntity rie = new RentInfoEntity();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HasPower())
            {
                Jscript.AlertAndGoBack("您权限不足，不能操作");
                return;
            }
            id = PageContext.GetRequest("id");
            if (string.IsNullOrEmpty(id))
            {
                Jscript.AlertAndGoBack("参数错误");
                return;
            }
            long iId = 0;
            long.TryParse(id, out iId);
            if (iId <= 0)
            {
                Jscript.AlertAndGoBack("参数错误");
                return;
            }
            rie = rib.GetEntityById(iId);
            if (rie == null)
            {
                Jscript.AlertAndGoBack("参数错误");
                return;
            }
            string action = PageContext.GetRequest("action");
            if (!string.IsNullOrEmpty(action))
            {
                this.DoAction(action, iId);
            }
        }

        protected bool DoAction(string action, long rid)
        {
            RentInfoBiz rif = new RentInfoBiz();
            RentInfoEntity rie = new RentInfoEntity();
            rie.Id = rid;
            rie.OptUserID = UserLogin.UserId;
            rie.ModifyTime = DateTime.Now;
            string strStartDate = PageContext.GetRequest("txtStartDate");
            if (!string.IsNullOrEmpty(strStartDate))
            {
                rie.StartDate = DateTime.Parse(strStartDate);
            }
            string strEntDate = PageContext.GetRequest("txtEndDate");
            if (!string.IsNullOrEmpty(strEntDate))
            {
                rie.EndDate = DateTime.Parse(strEntDate);
            }

            bool isSucc = rif.Update(rie, UserLogin);
            if (!isSucc)
            {
                Jscript.Alert("修改失败");
                return false;
            }

            Jscript.AlertAndRedirect("修改成功", "ZiyongModify.aspx?id=" + id);
            return true;
        }
    }
}